package com.model.defaults.actionbar.entities;

import java.util.Map;

import org.hibernate.Session;

import com.core.utils.GlobalConstants;
import com.model.ActionBarItem;
import com.model.ActionScript;
import com.model.KeyValue;
import com.model.UserContextName;

public class ModelDefaultActionbarItemsReport {

	public static void createActionBarItems ( Session session,
	                                          Map <String, UserContextName> userContexts ) {

		ModelDefaultActionbarItemsReport.createActionBarItemsReportAdd(session, userContexts);
		ModelDefaultActionbarItemsReport.createActionBarItemsReportList(session, userContexts);
		ModelDefaultActionbarItemsReport.createActionBarItemsReportOpen(session, userContexts);
		ModelDefaultActionbarItemsReport.createActionBarItemsReportUpdate(session, userContexts);

	}



	private static void createActionBarItemsReportList ( Session session,
	                                                     Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("servlet");
		actionScript.setActionScriptText(GlobalConstants.SERVLET_REPORTADD);
		session.save(actionScript);

		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_REPORTADD);
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_REPORTSLIST);
		pojo = new ActionBarItem();
		pojo.setName("actionbar.report.addreport");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}



	private static void createActionBarItemsReportOpen ( Session session,
	                                                     Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;

		KeyValue actionScriptParam = new KeyValue("p2", "?");
		actionScriptParam.setUserInfo(GlobalConstants.ACTIONSCRIPT_USERINFO_PARAM_KEY);
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("servlet");
		actionScript.setActionScriptText("%s?{p2}", GlobalConstants.SERVLET_REPORTUPDATE);
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_REPORTUPDATE);
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_REPORTINFO);
		pojo = new ActionBarItem();
		pojo.setName("actionbar.report.editdescription");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}



	private static void createActionBarItemsReportUpdate ( Session session,
	                                                       Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_REPORTUPDATE);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_REPORTUPDATE);

		KeyValue actionScriptParam = new KeyValue("form", "?");
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("javascript");
		actionScript.setActionScriptText("javascript:document.{form}.submit();");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		pojo = new ActionBarItem();
		pojo.setName("actionbar.report.updatedescription");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}



	private static void createActionBarItemsReportAdd ( Session session,
	                                                    Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_REPORTADD);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_REPORTUPDATE);

		KeyValue actionScriptParam = new KeyValue("form", "?");
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("javascript");
		actionScript.setActionScriptText("javascript:document.{form}.submit();");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		pojo = new ActionBarItem();
		pojo.setName("actionbar.report.savereport");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}
}
